The Smallest 'putbits' routine?
Introduction
Following on from the rather silly 'putbits' and 'getbits' articles, here is a simple code snippet to write a single bit into a datastream.
Could this be the smallest possible 'putbit' routine?
The code
The following should be pretty obvious. Call the 'init' with DS:DI pointing to the bitstream buffer then call 'putbit' with a single bit in the CF (carry flag). Use the 'flush' to align the final bits in the byte.
[DS:DI] --> bitstream buffer
CF --> the bit to write
init:
mov byte ptr [di],01h ; C6 05 01
ret ; C3
putbit:
mov byte ptr [di+1], 01h ; C6 45 01 01
rcl byte ptr [di], 1 ; D0 15
adc di, 0 ; 83 D7 00
ret ; C3
flush:
rcl byte ptr [di], 1 ; D0 15
jnc short flush ; 73 FC
inc di ; 47
ret ; C3
That's all folks.